function e(e, t, a) {
  return t in e ? Object.defineProperty(e, t, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = a, e;
}
var app = getApp();
var util = require('../../../utils/util.js');
var applet_park_api_url = app.globalData.applet_park_api_url;
const {
  requestDataparams
} = require('../../../utils/request.js');

function t(e) {
  return parseInt(e) < 10 && (e = "0" + e), e;
}

var a, s = require("../../../utils/calendar.js"), n = getApp();

Page({
  data: (a = {
    showStatus: true,
    rangeTime: [],
    currentDate: '',
    currentWeek: '',
    beginTime: '',
    endTime: '',
    selectedId: [],
    isContine: 'true',
    couponPrice:0,
    couponId:'',
    clickCount: 0,
    squareImg: '../../../images/duihao.png',
    checkIcon: false,
    meetingId:'',
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    circular: false,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
  }, e(a, "errorMessage", ""), e(a, "checkMessage", !1), e(a, "dialogDate", !1), e(a, "nowDateIndex", wx.getStorageSync("nowDateIndex")),
    e(a, "topDate", wx.getStorageSync("topDate")), e(a, "date_data1", []), e(a, "date_data2", []),
    e(a, "date_now", {
      month: "",
      year: "",
      value: ""
    }), e(a, "date_next", {
      month: "",
      year: "",
      value: ""
    }), e(a, "add_btn", !0), e(a, "reduce_btn", !1), e(a, "final_num", 1), e(a, "show_a", !1),
    e(a, "selecedList", []), e(a, "saleStatus", "nothing"), e(a, "saleContent", {}),
    e(a, "imgUrl", n.globalData.KrImgUrl), e(a, "cardStatus", "nothing"), e(a, "cardLength", 0),
    e(a, "discount", !1), e(a, "originalAmount", 0), a),

  changeProperty: function (e) {
    var propertyName = e.currentTarget.dataset.propertyName
    var newData = {}
    newData[propertyName] = e.detail.value
    this.setData(newData)
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  
  toPreDay: function (e) {
    var that = this;
    var nowData = that.getNowFormatDate();
    if (that.data.currentDate == nowData) {//当前时间没有前一天
      that.setData({
        nowDateIndex: 0
      })
    } else {//有前一天
      that.setData({
        nowDateIndex: 1
      })
      var dateTime = that.data.currentDate;
      var dd = new Date(dateTime);
      dd.setDate(dd.getDate() + 1);
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
      var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      var nextDay = y + "-" + m + "-" + d;
      that.setData({
        currentDate: nextDay
      })
      that.getTime(nextDay);
    }

  },
  toNextDay: function (e) {
    var that = this;
    var dateTime = that.data.currentDate;
    var dd = new Date(dateTime);
    dd.setDate(dd.getDate() + 1);
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
    var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    var nextDay = y + "-" + m + "-" + d;
    that.setData({
      currentDate: nextDay
    })
    that.getTime(nextDay);

  },
  getNowRangeTime: function () {
    var e = this.data.detailInfo.meetingRoomId, t = this, a = [], n = [];
    wx.showLoading({
      title: "加载中"
    });
    var i = new Date(), s = 2 * i.getHours() + 1 + (i.getMinutes() > 29 ? 1 : 0), r = this.data.selectedTime;
    o.getRequest({
      url: o.globalData.KrUrl + "api/gateway/krmting/room/disableTime",
      methods: "GET",
      data: {
        date: t.data.orderDate.time,
        meetingRoomId: e
      },
      header: {
        "content-type": "appication/json"
      },
      success: function (e) {
        a = e.data.data.disableTime;
        for (var i = 19; i < 49; i++) {
          var o = {
            disabled: !1,
            number: i,
            actived: !1
          };
          n.push(o);
        }
        n.forEach(function (e, n) {
          a.indexOf(e.number) > -1 && (e.disabled = !0), "今天" == t.data.orderDate.timeText && e.number < s && (e.disabled = !0),
            r.indexOf(e.number) > -1 && (e.actived = !0);
        }), t.setData({
          rangeTime1: n.slice(0, 8),
          rangeTime2: n.slice(8, 16),
          rangeTime3: n.slice(16, 24),
          rangeTime4: n.slice(24),
          rangeTime: n
        }, function () {
          wx.hideLoading();
        });
      }
    });
  },
  getThemeName: function (e) {
    var t = e.time.split("-"), a = "" + t[1] + t[2] + "会议";
    this.setData({
      orderDate: e,
      themeName: a
    }), this.choose_date = e.time;
  },
  dealDateList: function () {
    var e = this.data.nowDate, t = this.data.topDate, a = "";
    t.map(function (t) {
      t.date === e && (a = t.type);
    });
    var n = this;
    n.james = new i.dateData({
      btn_bool: !0,
      data: t,
      init_data: {
        last_btn_num: e,
        last_data: a
      }
    }), this.setData({
      date_data1: n.james.date_data1,
      date_data2: n.james.date_data2
    });
  },
  dateBtn: function (e) {
    this.james.dateBtn(e);
    var t = this.james.getValue();
    this.setData({
      date_data1: this.date_data1,
      date_data2: this.date_data2,
      selecedList: t
    });
  },
  onLoad: function (e) {
    var that = this;
    that.getNowFormatDate();//获取当前日期 
    that.getTime(that.data.currentDate);
    that.getMeetingRoomInfo();
  },
  getMeetingRoomInfo(){
    var that = this;
    wx.request({
      url: applet_park_api_url+'api/conferenceRooms/',
      method: 'GET',
      data: {},
      success(res) {
        if (res.data.code == 0) {
          var meetingRoomInfo = res.data.data;
          that.setData({
            meetingId: meetingRoomInfo.roomId,  //会议室id

          })
        } else {
          wx.showToast({
            title: '网络异常',
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: res.data,
        })
      }
    })
  },
  getNowFormatDate() {
    var that = this;
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var weekArr = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    var week = weekArr[date.getDay()];
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    that.setData({
      currentDate: currentdate,
      currentWeek: week
    })

    return currentdate;
  },
  getTime(data) {
    var that = this;
    wx.request({
      url: applet_park_api_url + 'api/conferenceRooms/scheduleTime',
      method: 'GET',
      data: {
        id: 1,
        day: data
      },
      success(res) {
        if (res.data.code == 0) {
          var timeList = res.data.data;
          var result = [];
          for (var i = 0; i < timeList.length; i += 8) {
            result.push(timeList.slice(i, i + 8));
          }
          that.setData({
            rangeTime: result,
            rowLength: result.length
          })
        } else {
          wx.showToast({
            title: '网络异常',
          })
        }


      },
      fail(res) {
        wx.showToast({
          title: res.data,
        })
      }
    })

  },
  enterCoupon(){//跳转优惠券
    //foreignType优惠券类型
    //foreignId会议室id
    var that = this;
    wx.navigateTo({
      url: "../../../pages/coupon_canteen/coupon_canteen?foreignType=2&foreignId=" + that.data.meetingId
    });
  },
  enterMember(){
    var that = this;
    wx.navigateTo({
      url: "../../pages/member/member"
    });
  },
  onClickDate: function () {
    var e = this, a = JSON.parse(JSON.stringify(this.combination_new)), s = 1;
    a && (this.combination_new = a.map(function (a) {
      return s = a.number, a.month = t(a.month), a.value = t(a.value), a.seat.weeks = e.getWeek(a.seat.useTime),
        a.seat.dates = a.seat.useTimeDescr.slice(0, 5), a;
    }), wx.setStorageSync("seat_sale_info", {
      card: !1,
      sale: !1
    }), this.getSaleContent(s));
  },
  jumpSetSale: function () {
    var e = {
      seatGoodIds: this.seatGoodIds,
      quantity: this.data.sankeNum
    };
    wx.setStorage({
      key: "seat-sale",
      data: e,
      success: function (e) {
        wx.navigateTo({
          url: "../saleList/saleList?from=seat"
        });
      }
    });
  },
  jumpSetCard: function () {
    var e = {
      seatGoodIds: this.seatGoodIds,
      quantity: this.data.sankeNum
    };
    wx.setStorage({
      key: "seat-sale",
      data: e,
      success: function (e) {
        wx.navigateTo({
          url: "../teamCardList/teamCardList?from=seat"
        });
      }
    });
  },
  heider: function (e) {
    "wrapper" == e.target.dataset.wrapper && this.setData({
      show_a: !0
    });
  },
  onShow: function () {
    var e = this.data.saleStatus, t = this.data.cardStatus, a = this.data.cardLength, s = this.data.saleLength, n = this;

    this.data.price_all;
    wx.getStorage({
      key: "order_pay",
      success: function (e) {
        0 != Object.keys(e.data).length && n.setData({
          themeName: e.data.themeName || n.data.themeName,
          remind: n.getRemind(e.data.alertTime) || n.getRemind("ONEDAY"),
          linkPhone: e.data.linkPhone || n.data.linkPhone,
          order_pay: e.data,
          alertTime: e.data.alertTime || "ONEDAY",
          referrerPhone: e.data.referrerPhone
        });
      }
    }), wx.getStorage({
      key: "seat_sale_info",
      success: function (o) {
        e = o.data.sale ? "chosen" : n.isFirst ? "new" : s > 0 ? "none" : "nothing", t = o.data.card ? "chosen" : a > 0 ? "none" : "nothing",
          n.setData({
            saleStatus: e,
            saleContent: o.data.sale,
            cardStatus: t,
            cardContent: o.data.card
          }, function () {
            n.getSeatcalculate();
          });
      }
    });
  },
  getSeatcalculate: function () {
    var e = this.data, t = this, a = {
      quantity: e.sankeNum,
      seatGoodIds: this.seatGoodIds
    };
    if (e.cardContent.id && (a.cardId = e.cardContent.id), e.saleContent.couponId && (a.couponId = e.saleContent.couponId),
      this.seatGoodIds) {
      var s = this.data.totalAmount;
      wx.getStorage({
        key: "seat_amount",
        success: function (e) {
          e.data.totalAmount && (s = e.data.totalAmount);
        }
      }), n.getRequest({
        url: n.globalData.KrUrl + "api/gateway/kmorder/seat/calculate",
        methods: "GET",
        data: a,
        success: function (a) {
          var n = a.data.data, o = {}, i = (t.data.cardStatus, t.data.saleStatus, {});
          if (1 == a.data.code) {
            n.cardId && (o = {
              cardName: n.cardName,
              remainAmountDecimal: n.cardDeductAmount,
              id: n.cardId
            }), n.couponId && (i = {
              couponId: n.couponId,
              amount: n.couponAmount
            }), t.isFirst = n.first || t.isFirst;
            var r = {
              totalAmount: n.totalAmount
            };
            wx.setStorage({
              key: "seat_amount",
              data: r
            }), t.setData({
              cardContent: o,
              saleContent: i,
              price_all: n.totalAmount,
              discount: n.discount,
              originalAmount: n.originalAmount
            });
          } else -5 == a.data.code ? (t.setData({
            price_all: s
          }), t.clearCard(e.sankeNum), t.setErrorMessage(a.data.message)) : -4 == a.data.code ? (t.setData({
            price_all: s
          }), t.clearSale(e.sankeNum), t.setErrorMessage(a.data.message)) : (t.setData({
            price_all: s
          }), t.setErrorMessage(a.data.message), t.getSaleContent(t.data.sankeNum));
        },
        fail: function (e) {
          t.setErrorMessage(e.data.message);
        }
      });
    }
  },
  setErrorMessage: function (e) {
    var t = this;
    this.setData({
      showError: !1,
      errorMessage: e
    }, function () {
      setTimeout(function () {
        t.setData({
          showError: !0,
          errorMessage: ""
        });
      }, 2e3);
    });
  },
  onUnload: function () {
    this.setData({
      carendarArr: {}
    });
  },
  createOrder: function () {
    var e = this;
    this.setData({
      dialogShow: !this.data.dialogShow
    });
    var t = this.data, a = this, s = {
      alertTime: t.alertTime,
      linkPhone: t.order_pay.linkPhone || t.linkPhone,
      arrivingTime: t.time,
      quantity: t.sankeNum,
      seatGoodIds: a.seatGoodIds,
      validAmount: t.price_all,
      first: a.isFirst,
      referrerPhone: t.order_pay.referrerPhone || ""
    };
    t.saleContent.couponId && (s.couponId = t.saleContent.couponId), t.cardContent.id && (s.cardId = t.cardContent.id),
      wx.showLoading({
        title: "加载中",
        mask: !0
      });
    var o = this;
    n.getRequest({
      url: n.globalData.KrUrl + "api/gateway/kmorder/seat/create",
      methods: "GET",
      header: {
        "content-type": "appication/json"
      },
      data: s,
      success: function (t) {
        var n = t.data.code;
        switch (setTimeout(function () {
          wx.hideLoading();
        }, 1500), n) {
          case -1:
            e.setData({
              checkMessage: !0,
              errorMessage: t.data.message
            }), setTimeout(function () {
              o.setData({
                checkMessage: !1,
                errorMessage: ""
              });
            }, 2e3);
            break;

          case -2:
            wx.setStorage({
              key: "create_seat",
              data: {
                create_seat: s
              }
            }), wx.navigateTo({
              url: "../bindPhone/bindPhone?fun=getSeatData"
            });
            break;

          case -4:
            setTimeout(function () {
              a.setData({
                dialogShow: !1,
                showError: !1,
                errorMessage: t.data.message,
                saleStatus: "none"
              });
            }, 1500), setTimeout(function () {
              a.setData({
                showError: !0,
                errorMessage: "",
                saleContent: {
                  sale: !1
                }
              }, function () {
                var e = a.data.sankeNum;
                a.getSaleContent(e);
              });
            }, 2e3);
            break;

          case 2:
            wx.showLoading({
              title: "加载中",
              mask: !0
            }), setTimeout(function () {
              wx.navigateTo({
                url: "../orderseatDetail/orderseatDetail?id=" + t.data.data.orderId + "&con=1"
              }), wx.hideLoading();
            }, 500);
            break;

          case 1:
            wx.setStorageSync("seat_sale_info", {
              sale: !1,
              card: !1
            });
            var i = t.data.data.wxPaySignInfo;
            wx.requestPayment({
              nonceStr: i.noncestr,
              orderId: i.orderId,
              package: i.packages,
              paySign: i.paySign,
              signType: i.signType,
              timeStamp: i.timestamp,
              success: function (e) {
                wx.showLoading({
                  title: "加载中",
                  mask: !0
                }), setTimeout(function () {
                  wx.navigateTo({
                    url: "../orderseatDetail/orderseatDetail?id=" + i.orderId + "&con=1"
                  }), wx.hideLoading();
                }, 1500);
              },
              fail: function (e) {
                wx.showLoading({
                  title: "加载中",
                  mask: !0
                }), wx.navigateTo({
                  url: "../orderseatDetail/orderseatDetail?id=" + i.orderId + "&con=1"
                });
              }
            });
            break;

          default:
            e.setData({
              checkMessage: !0,
              errorMessage: t.data.message,
              selectedTime: [],
              meeting_time: {
                time: "",
                beginTime: "",
                endTime: "",
                hours: 0
              }
            }), setTimeout(function () {
              o.setData({
                checkMessage: !1,
                errorMessage: ""
              });
            }, 2e3);
        }
      }
    });
  },
  setSaleStorage: function (e) {
    wx.getStorage({
      key: "seat_sale_info",
      success: function (t) {
        var a = t.data;
        "sale" == e ? a.sale = !1 : a.card = !1, wx.setStorage({
          key: "seat_sale_info",
          data: a
        });
      }
    });
  },
  tapTime: function (e) {
    var that = this;
    var nowIdArray = [];
    var nowTimeArray = [];
    var checkId = e.currentTarget.dataset.index;
    var checkTime = e.currentTarget.dataset.time;
    var timeState = e.currentTarget.dataset.state;
    var checkIdArray = that.data.selectedId;//被选中时间的id
    var selectedTimeArray = that.data.selectedTime;
    //判断所选时间的id是否存在
    if (checkIdArray.length > 0) {
      nowIdArray = checkIdArray.concat(checkId);
      nowIdArray = nowIdArray.sort();
      var nowContinue = that.isContinuityNum(nowIdArray);//返回是否连续
      if (nowContinue == false) {
        nowIdArray = nowIdArray.sort();
        if ((checkId == checkIdArray[0]) || (checkId == checkIdArray[checkIdArray.length - 1])) {
          //删除
          var index = checkIdArray.indexOf(checkId);
          that.judgeIcon(checkId, false);
          checkIdArray.splice(index, 1);
          that.setData({
            selectedId: checkIdArray
          })
        } else {
          nowIdArray = that.data.selectedId;
          wx: wx.showToast({
            title: '请选择连续的时间',
            icon: 'none',
            duration: 1000,
          })
        }

      } else {
        //添加
        that.judgeIcon(checkId, true);
        that.setData({
          selectedId: nowIdArray
        })
      }
    } else {
      that.judgeIcon(checkId, true);
      that.setData({
        selectedId: checkIdArray.concat(checkId),
      })
    }
    //处理时间
    var TimeList = that.data.rangeTime;
    for (var i = 0; i < that.data.selectedId.length; i++) {
      for (var j = 0; j < TimeList.length; j++) {
        var TimeItem = TimeList[j];
        for (var a = 0; a < TimeItem.length; a++) {

          if (that.data.selectedId[i] == TimeItem[a].timeId) {
            nowTimeArray = nowTimeArray.concat(TimeItem[a].time);
          }
        }
      }
    }
    that.setData({
      selectedTime: nowTimeArray
    })
    //判断时间区间  先找出开始时间和结束时间
    that.handleTimeSection(that.data.selectedTime);

  },
  judgeIcon(checkId, iconState) {
    var that = this;
    var TimeList = that.data.rangeTime;
    for (var i = 0; i < TimeList.length; i++) {
      var TimeItem = TimeList[i];
      for (var j = 0; j < TimeItem.length; j++) {
        if (checkId == TimeItem[j].timeId) {
          TimeItem[j].activity = iconState;
        }
      }
    }
    that.setData({
      rangeTime: TimeList
    })

  },
  isContinuityNum(num) {//判断是否连续
    var that = this;
    let array = [];
    if (num instanceof Array) {
      array = [...num];
    } else {
      array = Array.from(num.toString())//转换为数组
    }

    var i = array[0];
    var isContinuation = true;
    for (var e in array) {
      if (array[e] != i) {
        isContinuation = false;
        break;
      }
      i++;
    }
    return isContinuation;
  },
  judgeRepeat(checkTime, selectedTimeArray) {//判断选中的日期是否存在
    var that = this;
    for (var i = 0; i < selectedTimeArray.length; i++) {
      var index = selectedTimeArray.indexOf(checkTime);
      if (index > -1) {
        selectedTimeArray.splice(index, 1);//存在就删除
      } else {
        that.setData({
          selectedTime: selectedTimeArray.concat(checkTime),
        })
      }
    }

  },
  handleTimeSection(section) {//先找出开始时间和结束时间
    var that = this;
    var maxTime = '';//最大的时间
    var minTime = '';//初始时间
    var newSection = [];
    for (var i = 0; i < section.length; i++) {
      newSection = newSection.concat(that.data.currentDate + " " + section[i]);
    }
    //sort按时间正序排序
    newSection.sort(function (a, b) {
      return Date.parse(b.time) - Date.parse(a.time);
    });
    maxTime = newSection[newSection.length - 1];
    minTime = newSection[0];
    that.handleTime(maxTime, minTime)
  },
  handleTime(val, minTime) {
    var that = this;
    var val = val;
    var sdate1 = new Date(val);
    sdate1.setMinutes(sdate1.getMinutes() + 30);
    var nowHours = sdate1.getHours();
    var nowMinutes = sdate1.getMinutes() > 9 ? sdate1.getMinutes().toString() : '0' + sdate1.getMinutes();
    var now = nowHours + ":" + nowMinutes;
    var endtime = that.data.currentDate + " " + now;
    that.setData({
      beginTime: minTime,
      endTime: endtime
    })
  },
  actionHide: function () {
    var that = this;
    that.setData({
      showStatus: true,
    });
  },
  actionShow: function () {
    var that = this;
    that.setData({
      showStatus: false,
    });
  },
});